package com.atguigu.juc_day02;

import java.util.concurrent.CountDownLatch;

/**
 * java
 * 2022/9/9 01 00
 */
class Student2{
    private int num = 6;
    public synchronized void out() throws InterruptedException {
        while (num==0){
            wait ();
        }
        System.out.println (Thread.currentThread ().getName ()+"剩余"+ --num);
        notify ();
    }
}
public class CountDownLatchDemo02 {
    public static void main (String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch (6);
        Student2 student2 = new Student2 ();
        for (int i = 0; i < 6; i++) {
            new Thread (()->{

                try {
                    student2.out ();
                } catch (InterruptedException e) {
                    throw new RuntimeException (e);
                }
                countDownLatch.countDown ();
            }).start ();
        }
        countDownLatch.await ();
        System.out.println ("班长走了");
    }
}
